package com.sf.mysql.tool.excel;

import jxl.Workbook;
import jxl.write.DateTime;
import jxl.write.Label;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import jxl.write.Number;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import java.io.File;
import java.io.FileInputStream;
import java.util.Date;

/**
 * @author Administrator
 */
public class ReadExcel {
    private static final String EXCEL_PATH = "src/main/resources/dataBaseDemo.xlsx";

    public static void main(String[] args) throws Exception{
        printExcel(EXCEL_PATH);
    }

    public static void printExcel(String excelPath) throws Exception {
        XSSFWorkbook wb = new XSSFWorkbook(new FileInputStream(excelPath));
        // 读取文件中的第一张表格
        System.out.println("页码共>>" + wb.getNumberOfSheets());
        for (int sh = 0; sh < wb.getNumberOfSheets(); sh++) {
            XSSFSheet sheet = wb.getSheetAt(sh);
            XSSFRow row;
            // XSSFCell cell;
            String cell;

            for (int i = sheet.getFirstRowNum(); i < sheet.getPhysicalNumberOfRows(); i++) {
                row = sheet.getRow(i);
                for (int j = row.getFirstCellNum(); j < row.getPhysicalNumberOfCells(); j++) {
                    cell = row.getCell(j).toString();
                    System.out.print(cell + "\t");
                }
                System.out.println("");
            }
        }

        wb.close();
    }
}
